package ar.edu.unlp.info.cptn.view;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.view.document.AbstractPdfView;

import ar.edu.unlp.info.cptn.model.Persona;

import com.lowagie.text.BadElementException;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Table;
import com.lowagie.text.pdf.PdfWriter;

public class PDFReportView extends AbstractPdfView {

	@Override
	protected void buildPdfDocument(Map<String, Object> model,Document document, PdfWriter writer, HttpServletRequest request,HttpServletResponse response) {

		List<Persona> personas = (List<Persona>) model.get("personas");

		Table table;
		try {
			table = new Table(2);
			table.addCell("Nombre");
			table.addCell("Apellido");

			for (Persona persona : personas) {
				table.addCell(persona.getNombre());
				table.addCell(persona.getApellido());
			}

			document.add(table);
		} catch (BadElementException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (DocumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

}
